package 反射第一遍.demo13;

import java.lang.reflect.Field;

/**
 * @author wql
 * @version 1.0
 * @date 2022/10/27 14:57
 */

public class Test {
    public static void main(String[] args) throws Exception{
        Class<apple> aClass = apple.class;
        apple apple = aClass.newInstance();
        Field address = aClass.getDeclaredField("address");
        address.set(apple,"北京");
        System.out.println("apple = " + apple);

        Object o = address.get(apple);
        System.out.println("o = " + o);

        Field num = aClass.getDeclaredField("num");
        num.setAccessible(true);
        num.set(apple,5);
        System.out.println("apple = " + apple);

        Object o1 = num.get(apple);
        System.out.println("o1 = " + o1);
    }
}
class vegetable{
    public  String name;
    private Integer price;

}
class apple extends vegetable {
    public String address;
    private Integer num;

    @Override
    public String toString() {
        return "apple{" +
                "address='" + address + '\'' +
                ", num=" + num +
                '}';
    }
}
